package com.payment.service.impl;

import com.payment.entity.common.OrderPaymentManager;
import com.payment.entity.common.OrderRefPackageManager;
import com.payment.entity.common.UserboundPaymentOrder;
import com.payment.mapper.OrderPaymentManagerMapper;
import com.payment.service.OrderPaymentManagerService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional
public class OrderPaymentManagerServiceImpl implements OrderPaymentManagerService {
    @Resource
    OrderPaymentManagerMapper orderPaymentManagerMapper;

    @Override
    public void storageOrderPayment(OrderPaymentManager userOrder) {
        orderPaymentManagerMapper.storageOrderPayment(userOrder);
    }

    @Override
    public void updateOrderIdByRequestOrderIdAndDeviceId(OrderPaymentManager user) {
        orderPaymentManagerMapper.updateOrderIdByRequestOrderIdAndDeviceId(user);
    }

    @Override
    public void updateIsOpenAndNotify(OrderPaymentManager userOrder) {
        orderPaymentManagerMapper.updateIsOpenAndNotify(userOrder);
    }

    @Override
    public List<OrderPaymentManager> getListToOpen() {

        return orderPaymentManagerMapper.getListToOpen();
    }

    @Override
    public int findOrderIdByNotify(String orderId) {
        return orderPaymentManagerMapper.findOrderIdByNotify(orderId);
    }

    @Override
    public void updateIsNotify(OrderPaymentManager paymentOrder) {
        orderPaymentManagerMapper.updateIsNotify(paymentOrder);
    }

    @Override
    public List<OrderPaymentManager> getOrderResultsList(String orderId, String deviceId) {
        return orderPaymentManagerMapper.getOrderResultsList(orderId, deviceId);
    }

    @Override
    public void updateIsChannelNotity(OrderPaymentManager paymentOrder) {
        orderPaymentManagerMapper.updateIsChannelNotity(paymentOrder);
    }

    @Override
    public List<OrderPaymentManager> getChannelResultList() {
        return orderPaymentManagerMapper.getChannelResultList();
    }

    @Override
    public void insertRefPackage(OrderRefPackageManager ref) {
        orderPaymentManagerMapper.insertRefPackage(ref);
    }

    @Override
    public void UpdatePaypalNotify(UserboundPaymentOrder order) {
        orderPaymentManagerMapper.UpdatePaypalNotify(order);
    }

    @Override
    public int findDataByRequestOrderId(String requestOrderId, String deviceId, String orderPeriod, String partnerCode, String packageCode) {
        return orderPaymentManagerMapper.findDataByRequestOrderId(requestOrderId, deviceId, orderPeriod, partnerCode, packageCode);
    }

    @Override
    public UserboundPaymentOrder queryPaymentOrderByOrderId(String orderId, String amount) {
        return orderPaymentManagerMapper.queryPaymentOrderByOrderId(orderId, amount);
    }

    @Override
    public void updateIsNotifyOrderT(OrderPaymentManager paymentManager) {
        orderPaymentManagerMapper.updateIsNotifyOrderT(paymentManager);
    }

    @Override
    public void UpdatePaypalNotifyById(UserboundPaymentOrder order) {
        orderPaymentManagerMapper.UpdatePaypalNotifyById(order);
    }

    /**
     * 查询数据库里面有没有这条回调数据
     *
     * @param orderNo
     * @return
     */
    @Override
    public Integer findOrderCodeByNotify(String orderNo) {
        return orderPaymentManagerMapper.findOrderCodeByNotify(orderNo);
    }

    /**
     * 回调数据更新数据表
     *
     * @param paymentOrder
     */
    @Override
    public Integer updatePayRstById(OrderPaymentManager paymentOrder) {
        return orderPaymentManagerMapper.updatePayRstById(paymentOrder);
    }

    /**
     * 根据上报的orderNo和requestOrderId查询订单记录
     *
     * @param orderNo
     * @param requestOrderId
     * @return
     */
    @Override
    public OrderPaymentManager queryOrderByOrderId(String orderNo, String requestOrderId) {
        return orderPaymentManagerMapper.queryOrderByOrderId(orderNo, requestOrderId);
    }

    /**
     * 去数据库更新orderId等字段
     *
     * @param order
     * @return
     */
    @Override
    public Integer updateOrderId(OrderPaymentManager order) {

        return orderPaymentManagerMapper.updateOrderId(order);
    }

    /**
     * payPal-webHook 回调去入库：user_order_payment_manager_t
     *
     * @param paymentOrder
     * @return
     */
    @Override
    public Integer updatePayRst(OrderPaymentManager paymentOrder) {

        return orderPaymentManagerMapper.updatePayRst(paymentOrder);
    }

    /**根据orderNo查询订单对象
     * @param orderNo
     * @return
     */
    @Override
    public OrderPaymentManager queryOrderByOrderNo(String orderNo) {
return orderPaymentManagerMapper.queryOrderByOrderNo(orderNo);
    }

}
